<?php
//日志记录模型
class LogModel extends CommonModel {
	
	/**
	 * 日志记录
	 * @param int    $cid       栏目id
	 * @param string $action    操作        |   增加 add  删除 delete 修改 update
	 * @param string $desc      操作描述 
	 */
	public function writeLog($cid,$action,$operateid,$desc)
	{
		if(!$cid || !$action) return;
		$data['cid'] = $cid;
		$data['action'] = $action;
		$data['operateid'] = intval($operateid);
		$data['desc'] = $desc;
		$data['dateline'] = time();
		//记录日志
		$ret = $this->add($data);
	}
	
	public function getLogList($cid)
	{
		$where = $list = $page = '';
		if($cid) $where = " and log.cid = $cid ";
		$count = $this->where($where)->count();
		if($count > 0)
		{
				import("@.ORG.Page");
				$p = new Page($count,10);
				$where = $where ? ' where '.$where : '';
				$sql="select 
						co.column_name,log.*
				  from 
				  		douhao_website_column as co  ,
				  		douhao_log as `log`
				  where
				        co.id = log.cid and co.status = '1' 
				        $where 
				   order by log.dateline desc
				   limit $p->firstRow , $p->listRows
			      ";
			    $list = $this->query($sql); 
			    $page = $p->show();
		}	
		return array('list'=>$list,'page'=>$page);
	}
}
?>